<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Users;
use App\Models\Usersauthority;
use App\Models\Linkslists;
use App\Models\Memberorders;
use App\Models\Linkslistsservicesusers;
use App\Models\Linkslistsservices;
use App\Models\Linkslistsviews;
use App\Models\Linkslistsminapps;
use App\Models\Linkslistsips;
use App\Models\Linkslistsshorts;
use App\Models\Linkslistsqrcodes;
use App\Models\Usersqrcodelists;
use App\Models\Linkslistsstyles;
use App\Models\Linkslistskefu;
use App\Models\Linksliststhird;
use App\Models\Linkslistssetting;
use App\Models\Linksliststotal;
use App\Jobs\Htmlosshanndle;
use App\Services\WechatService;
use App\Services\CommonService;
use App\Services\BaiduService;
use App\Services\MiniappService;
use App\Services\CacheService;
use App\Services\LinkscheckService;
use App\Services\OutputService;
use App\Services\HtmlossService;
use Cookie,Log,Exception;

class LinksController extends Controller
{
    public function linksPublist(Request $request,$version)
    {
        if ($request->users_id == "4606") {
            $msg = json_decode($request->msg);
            if ($msg->mini_id == "wx3277e643ee0886e0") {
                $path = explode("?",$msg->path);
                $query = count($path) > 1 ? "&query=".urlencode($path[1]) : "";
                $url = "https://s.pdb2.com/l/cmEpiL42gA?path=".urlencode($path[0]).$query;
                return response()->json(["status"=>"success","code"=>"1000","msg"=>"链接创建成功！","data"=>["url"=>$url]]);
            }
        }
        Log::info("linksPublist-----------");
        Log::info($request->all());
        Log::info("linksPublist-----------");
        return OutputService::error("接口已升级,请前往天天外链后台使用!");
    }

    public function linksUpdate(Request $request)
    {
        return OutputService::error("维护中,请稍后使用!");
    }

    // 小程序获取链接列表
    public function usersLinksLists(Request $request)
    {
        $links = Linkslists::getUsersLinks($request->users_id);
        return response()->json(["status"=>"success","code"=>"1000","msg"=>"链接列表获取成功！","data"=>$links]);
    }

    // 案例链接列表
    public function demoLinksLists(Request $request)
    {
        $links = Linkslists::getdemoLinks();
        $links_ids = collect($links)->pluck("links_id");
        $linksdatats = Linkslistsips::getAllListsViewsDatas($links_ids);
        foreach ($links as $link) {
            // $link->pv = collect($linksdatats)->where("links_id",$link->links_id)->sum("count");
            // $link->miniapp_pv = collect($linksdatats)->where("links_id",$link->links_id)->whereIn("status",[2,3])->sum("count");
            $link->pv = 8888;
            $link->miniapp_pv = 8000;
            if ($link->links_id == "CMfpePb23A") {
                $link->platfrom_type = 12;
            }
        }
        return response()->json(["status"=>"success","code"=>"1000","msg"=>"链接列表获取成功！","data"=>$links]);
    }

    // 我的小程序列表
    public function usersLinksListsMinapps(Request $request)
    {
        $minapps = Linkslistsminapps::getUsersMinapps($request->users_id);
        return response()->json(["status"=>"success","code"=>"1000","msg"=>"小程序列表获取成功！","data"=>$minapps]);
    }

    // 小程序添加
    public function usersLinksListsMinappsAdd(Request $request)
    {
        if (empty($request->name)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请输入小程序名称！"]);
        if (mb_strlen($request->name) > 35) return response()->json(["status"=>"error","code"=>"1001","msg"=>"小程序名称不能超过35位！"]);
        if (empty($request->appid)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请输入小程序Appid！"]);
        if (empty($request->secret)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请输入小程序Secret！"]);
        if (empty($request->original_id)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请输入小程序原始ID！"]);

        if (strlen($request->appid) != 18 || mb_substr($request->appid,0,2) != "wx") return response()->json(["status"=>"error","code"=>"1001","msg"=>"请输入正确的Appid!"]);
        if (strlen($request->secret) != 32) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请输入正确的AppSecret!"]);
        if (strlen($request->original_id) != 15 || mb_substr($request->original_id,0,3) != "gh_") return response()->json(["status"=>"error","code"=>"1001","msg"=>"请输入正确的原始ID！!"]);

        $minapps = Linkslistsminapps::getLinksListsMinappsByAppid($request->appid);
        if (!empty($minapps) && $minapps->disable != 2) return response()->json(["status"=>"error","code"=>"1002","msg"=>"小程序已存在,请不要重复添加！"]);
        // 验证密钥是否正确
        $appsecret_right = WechatService::appsecretRight($request->appid,$request->secret);
        // 密钥错误不能添加
        if ($appsecret_right["status"] == "error") return response()->json(["status"=>"error","code"=>"1002","msg"=>$appsecret_right["msg"]]);
        // 添加小程序
        $type = empty($request->type) ? 1 :$request->type;
        Linkslistsminapps::linksListsMinappsInsert($request->name,$request->appid,$request->secret,$request->users_id,1,1,$request->original_id,$type,1);
        return response()->json(["status"=>"success","code"=>"1000","msg"=>"小程序添加成功。"]);
    }

    // 小程序更新
    public function usersLinksListsMinappsUpdate(Request $request)
    {
        if (empty($request->name)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请输入小程序名称！","data"=>[]]);
        if (empty($request->appid)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请输入小程序Appid！","data"=>[]]);
        if (empty($request->secret)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请输入小程序Secret！","data"=>[]]);
        if (empty($request->original_id)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请输入小程序原始ID！","data"=>[]]);

        if (strlen($request->appid) != 18 || mb_substr($request->appid,0,2) != "wx") return response()->json(["status"=>"error","code"=>"1001","msg"=>"请输入正确的Appid!","data"=>[]]);
        if (strlen($request->secret) != 32) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请输入正确的AppSecret!","data"=>[]]);
        if (strlen($request->original_id) != 15 || mb_substr($request->original_id,0,3) != "gh_") return response()->json(["status"=>"error","code"=>"1001","msg"=>"请输入正确的原始ID！!","data"=>[]]);

        $minapps = Linkslistsminapps::getLinksListsMinappsByAppid($request->appid);
        if (empty($minapps)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"小程序不存在!","data"=>[]]);
        $users = Users::getUsersDetial($request->users_id);
        if ($users->authority != 3 && $minapps->users_id != $request->users_id) return response()->json(["status"=>"error","code"=>"1001","msg"=>"小程序不存在!","data"=>[]]);

        if (!empty($minapps) && $minapps->id != $request->id) return response()->json(["status"=>"error","code"=>"1002","msg"=>"小程序已存在,不能更新成此小程序！","data"=>[]]);
        // 验证密钥是否正确
        $appsecret_right = WechatService::appsecretRight($request->appid,$request->secret);
        // 密钥错误不能添加
        if ($appsecret_right["status"] == "error") return response()->json(["status"=>"error","code"=>"1002","msg"=>$appsecret_right["msg"]]);
        Linkslistsminapps::linksListsMinappsUpdate($request->id,$request->name,$request->appid,$request->secret,$request->users_id,1,$request->disable,$request->original_id);
        return response()->json(["status"=>"success","code"=>"1000","msg"=>"小程序更新成功。","data"=>[]]);
    }

    // 小程序获取链接列表
    public function usersLinksDetial(Request $request)
    {
        if (empty($request->links_id)) return OutputService::error("参数错误!");
        $links = Linkslists::apiLinksSimple($request->links_id);
        if (empty($links)) return OutputService::error("外链不存在！");
        if ($links->users_id != 7) {
            try {
                $users_id = decrypt($request->users_id);
            } catch (Exception $e) {
                return OutputService::error("参数错误!");
            }
            if ($links->users_id != 7 && $users_id != $links->users_id) return OutputService::error("外链不存在！");

            $member = Memberorders::getLastLinksOrders($users_id);
            // 免费用户和付费用户的链接不同
            if (empty($member) || $member->end_time <= time()) {
                $links_url = config("spare_urls.freeurl")."/l/".$links->links_id;
            } else {
                $links_url = config("spare_urls.paidurl")."/l/".$links->links_id;
            }
        } else {
            $links_url = config("spare_urls.freeurl")."/l/".$links->links_id;
        }
        $links->url = $links_url;
        $demo_gifs = ["","1.gif","2.gif","2.gif","4.gif","4.gif","6.gif","7.gif","8.gif","8.gif","11.gif","8.gif"];
        $demo_gif = isset($demo_gifs[$links->platfrom_type]) ? $demo_gifs[$links->platfrom_type] : "1.gif";
        $links->demo_gif = "https://nilife.oss-cn-beijing.aliyuncs.com/miniapp/images/gif/".$demo_gif;
        $links->urls = [["name"=>"通用链接","image"=>"/static/logo.png","url"=>$links_url],["name"=>"微博专用","image"=>"https://nilife.oss-cn-beijing.aliyuncs.com/wepage/20210601-115433-835.jpeg","url"=>config("spare_urls.weibourl")."/l/".$links->links_id],["name"=>"群发专用","image"=>"https://nilife.oss-cn-beijing.aliyuncs.com/wepage/20210601-115146-915.png","url"=>config("spare_urls.groupurl")."/l/".$links->links_id]];
        $links->urlstitle = "请根据用途复制对应外链";
        $links->detial_describe = "商用前请添加客服微信；大流量(5万/日)推广前请务必联系客服获取活动专属链接！";
        $links->copy_describe = "提示：复制链接后请使用浏览器打开。";
        if (in_array($links->platfrom_type, [2,3])) {
            $links->platfrom = 3;
        } elseif(in_array($links->platfrom_type, [4,5,6])) {
            $links->platfrom = 2;
        } else {
            $links->platfrom = 1;
        }
        if (in_array($links->platfrom_type, [8,9,11,12])) {
            $qrcodes = Linkslistsqrcodes::getLinksListsQrcodes($links->links_id);
            $links->msg = json_encode($qrcodes->pluck("img_url")->all());
        }
        return response()->json(["status"=>"success","code"=>"1000","msg"=>"链接详情获取成功！","data"=>$links]);
    }

    // 小程序更新获取数据
    public function usersLinksUpdateDetial(Request $request)
    {
        if (empty($request->links_id)) return OutputService::error("参数错误!");
        $links = Linkslists::getLinks($request->links_id);
        if (empty($links)) return OutputService::error("外链不存在！");
        if ($request->users_id != $links->users_id) return OutputService::error("外链不存在！");
        $listsSetting = Linkslistssetting::getLinksListsSetting($request->links_id);

        $miniapp = [];
        $qrcodeLists = [];
        if ($links->platfrom_type == 6) {
            $miniapp = Linksliststhird::getLinksListsThird($links->links_id);
        } elseif (in_array($links->platfrom_type, [8,9,11,12])) {
            $qrcodeLists = Linkslistsqrcodes::apiAllLinksListsQrcodes($links->links_id);
        }

        $links_lists = ["links_id"=>$links->links_id,"title"=>$links->title,"original_id"=>$links->original_id,"appid"=>$links->appid,"miniapp_type"=>$links->miniapp_type,"path"=>$links->path,"platfrom"=>$links->platfrom,"platfrom_type"=>$links->platfrom_type,"qrcode_switch"=>$links->qrcode_switch,"qrcode_upper"=>$links->qrcode_upper,"qrcode_daily"=>$links->qrcode_daily,"nike"=>$listsSetting->nike,"wechat"=>$links->wechat,"describe"=>$links->describe,"qrcode_notice"=>$listsSetting->qrcode_notice,"button_show"=>$listsSetting->button_show,"button_text"=>$listsSetting->button_text,"service_notice"=>$listsSetting->service_notice,"service_image"=>$listsSetting->service_image,"miniapp_style"=>$listsSetting->miniapp_style,"miniapp"=>$miniapp,"services"=>[],"msg_url"=>$links->msg,"logo"=>$listsSetting->logo,"qrcodeLists"=>$qrcodeLists];
        return OutputService::success("SUCCESS",$links_lists);
    }

    // 小程序链接删除
    public function usersLinksDelete(Request $request)
    {
        $links = Linkslists::getLinks($request->links_id);
        if (empty($links)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"删除失败，链接不存在！"]);
        if ($links->users_id != $request->users_id) return response()->json(["status"=>"error","code"=>"1001","msg"=>"删除失败，链接不存在！"]);
        Linkslists::linksListsDisable($request->users_id,$request->links_id);
        // 删除短链接缓存数据
        CacheService::removeLinksCache($request->links_id);
        // 删除线上文件
        HtmlossService::aliossHtmlDelete($request->links_id,$links->created_at);
        return response()->json(["status"=>"success","code"=>"1000","msg"=>"链接删除成功！"]);
    }

    // 获取创建界面参数
    public function linksSubmitInfo(Request $request)
    {
        $minapps = Linkslistsminapps::getPlatfromUseableDefaultMinapps(6);
        $info = ["wechat_name"=>"请注意：公众号需关联【".$minapps->name."】小程序。","wechat_appid"=>$minapps->appid,"wechat_miniapp_name"=>$minapps->name,"wechat_miniapp_spare"=>"极速跳转中","wechat_appid_text"=>"APPID：".$minapps->appid." 【点击复制】","demo_one"=>"例: QQ私信引流关注公众号","demo_two"=>"例: 必须已发布的公众号文章链接https://mp.weixin.qq.com","demo_miniid"=>"例: ".$minapps->appid,"demo_mini_description"=>"例: 点击立即领取优惠券","demo_kefu_description"=>"例: 点击立即联系客服","demo_path"=>"例: page/index/index?id=123","demo_article"=>"用富文本编辑的文章。","demo_kefu"=>"编辑客服回复的内容"];
        return response()->json(["status"=>"success","code"=>"1000","msg"=>"获取成功","data"=>$info]);
    }

    public function linksListsh5Update(Request $request)
    {
        $links_id = $request->links_id;
        $links = Linkslists::getLinks($links_id);
        if (empty($links)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"外链不存在！"]);
        if ($request->users_id != $links->users_id) return response()->json(["status"=>"error","code"=>"1001","msg"=>"外链不存在！"]);

        $member = Memberorders::getLastLinksOrders($request->users_id);
        if (empty($member)) return response()->json(["status"=>"error","code"=>"1005","msg"=>"高级版/旗舰版会员才能使用本功能！"]);
        if ($member->product_id <= 2) return response()->json(["status"=>"error","code"=>"1005","msg"=>"高级版/旗舰版会员才能使用本功能！"]);
        if (empty($member) || $member->end_time <= time()) return response()->json(["status"=>"error","code"=>"1005","msg"=>"高级版/旗舰版会员才能使用本功能！"]);
        if($request->style == 4 && empty($request->redirect_url)){
            return response()->json(["status"=>"error","code"=>"1006","msg"=>"一键审核跳转地址不能为空"]);
        }
        $redirect_url = empty($request->redirect_url) ? 'http' : $request->redirect_url;
        if (empty($request->button_text_color)) {
            Linkslistsstyles::updateLinksListsStyles($links_id,["style"=>$request->style,"logo"=>$request->logo,"redirect_url"=>$redirect_url]);
        } else {
            Linkslistsstyles::updateLinksListsStyles($links_id,["style"=>$request->style,"logo"=>$request->logo,"button_border"=>$request->button_border,"button_background_color"=>$request->button_background_color,"button_text_color"=>$request->button_text_color,"botton_text"=>$request->botton_text,"postion"=>$request->postion,"gif_show"=>$request->gif_show,"redirect_style"=>$request->redirect_style,"redirect_url"=>$redirect_url]);
        }
        // 删除短链接缓存数据
        CacheService::removeLinksCache($links_id);
        // 更新线上OSS
        Htmlosshanndle::dispatch($links->users_id,$links->links_id,$links->created_at)->delay(10);
        return response()->json(["status"=>"success","code"=>"1000","msg"=>"外链样式修改成功。"]);
    }

    public function shortCode(Request $request)
    {
        $links_id = $request->links_id;
        $link = Linkslists::getLinks($links_id);
        if (empty($link)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"外链不存在！"]);
        if ($request->users_id != $link->users_id) return response()->json(["status"=>"error","code"=>"1001","msg"=>"外链不存在！"]);

        $member = Memberorders::getLastLinksOrders($request->users_id);
        if (empty($member) || $member->end_time <= time()) return response()->json(["status"=>"error","code"=>"1005","msg"=>"开通会员才能使用本功能！"]);
        $shortlinks = Linkslistsshorts::getLinksListsShorts($links_id);
        if (empty($shortlinks)) {
            $short_id = CommonService::decb64(time().$link->id);
            Linkslistsshorts::insertLinksListsShort($links_id,$short_id,$link->created_at->getTimeStamp());
        } else {
            $short_id = $shortlinks->short_id;
        }
        return response()->json(["status"=>"success","code"=>"1000","msg"=>"获取短链接成功。","data"=>["url"=>"https://".config("spare_urls.shorturl")."/d/".$short_id]]);
    }

    public function services(Request $request)
    {
        // 首次绑定验证接口
        if (isset($request->echostr)) return WechatService::servicesFirstSetting($request->signature,$request->timestamp,$request->nonce,$request->echostr);
        // 用户的 OpenID
        $openid = $request->FromUserName;
        // 点击进入客服时,判断平台返回对应数据：
        if ($request->MsgType == "event") {
            $SessionFrom = ($request->SessionFrom == "cee8a69c9b1c4f1999084026827516fb") ? "cm5krpSPrEO" : $request->SessionFrom;
            $links = Linkslists::getLinks($SessionFrom);
            if (empty($links)) return false;
            // 获取客服用户信息
            $linksListsUsers = Linkslistsservicesusers::getLinksListsUsers($links->users_id,$openid,$SessionFrom);
            // 创建交流客户
            if (empty($linksListsUsers)) {
                $links_lists_users_id = Linkslistsservicesusers::insertLinksListsUsers($links->users_id,$openid,$SessionFrom);
            } else {
                // 更新访问时间,然后根据时间排序,这样回复不会乱
                Linkslistsservicesusers::updateLinksListsTime($linksListsUsers->id);
                $links_lists_users_id = $linksListsUsers->id;
            }

            // 创建访问记录
            Linkslistsservices::insertLinksListsServices($links->users_id,$links_lists_users_id,"用户进入会话",1,"",$request->CreateTime,$SessionFrom,1,1);

            if (in_array($links->platfrom_type,[2,3])) {
                $listskefus = Linkslistskefu::getCountLinksListsKefu($links->links_id,3);
                // 默认最多发送3条,留2条后续再次进入
                foreach ($listskefus as $key=>$listskefu) {
                    WechatService::getServiceParams($listskefu,$openid,$request->ToUserName,$links->links_id);
                    // 进入页面回复3条
                    Linkslistsservices::insertLinksListsServices($links->users_id,$links_lists_users_id,"进入页面回复".$listskefu["id"],$listskefu["type"],"",time(),$SessionFrom,2,$listskefu["id"]);
                }
            } else {
                return false;
            }
        // 点击小程序的提示
        } elseif ($request->MsgType == "miniprogrampage") {
            $listsusers = Linkslistsservicesusers::getLinksListsUsersSimple($openid);
            if (empty($listsusers)) return false;

            $content = $request->Title;
            // 创建客服聊天记录
            Linkslistsservices::insertLinksListsServices($listsusers->users_id,$listsusers->id,$content,4,$request->MsgId,$request->CreateTime,$listsusers->links_id,1,1);

            $links = Linkslists::getLinks($listsusers->links_id);
            if (in_array($links->platfrom_type,[2,3])) {
                $listskefus = Linkslistskefu::getCountLinksListsKefu($links->links_id,3);
                // 默认最多发送3条,留2条后续再次进入
                foreach ($listskefus as $key=>$listskefu) {
                    WechatService::getServiceParams($listskefu,$openid,$request->ToUserName,$links->links_id);
                    // 进入页面回复3条
                    Linkslistsservices::insertLinksListsServices($links->users_id,$listsusers->id,"进入页面回复".$listskefu["id"],$listskefu["type"],"",time(),$listsusers->links_id,2,$listskefu["id"]);
                }
            } else {
                return false;
            }
        } else {
            $listsusers = Linkslistsservicesusers::getLinksListsUsersSimple($openid);
            if (empty($listsusers)) return false;
            // 创建聊天记录
            if ($request->MsgType == "text") {
                $type = 2;
                $content = $request->Content;
            } elseif ($request->MsgType == "image") {
                $type = 3;
                $content = $request->PicUrl;
            } else {
                $type = 4;
                $content = json_encode(["Title"=>$request->Title,"AppId"=>$request->AppId,"PagePath"=>$request->PagePath,"ThumbUrl"=>$request->ThumbUrl,"ThumbMediaId"=>$request->ThumbMediaId]);
            }
            // 创建客服聊天记录
            Linkslistsservices::insertLinksListsServices($listsusers->users_id,$listsusers->id,$content,$type,$request->MsgId,$request->CreateTime,$listsusers->links_id,1,1);
            // 获取最后一次回复记录
            $lastServices = Linkslistsservices::getLastLinksListsServices($listsusers->users_id,$listsusers->id,$listsusers->links_id);
            $lastid = isset($lastServices) ? $lastServices->step : 1;
            $listskefu = Linkslistskefu::getNextLinksListsKefu($listsusers->links_id,$lastid);
            if (empty($listskefu)) return false;
            WechatService::getServiceParams($listskefu,$openid,$request->ToUserName,$listsusers->links_id);
            // 二次回复
            Linkslistsservices::insertLinksListsServices($listsusers->users_id,$listsusers->id,"二次回复",$listskefu["type"],$request->MsgId,time(),$listsusers->links_id,2,$listskefu["id"]);
        }
    }

    public function apiGetAccessToken(Request $request)
    {
        if (empty($request->appid)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请输入APPID！"]);
        $miniapps = Linkslistsminapps::getLinksListsMinappsByAppid($request->appid);
        if (empty($miniapps)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"小程序不存在！"]);
        if ($request->users_id != $miniapps->users_id) return response()->json(["status"=>"error","code"=>"1001","msg"=>"小程序不存在！"]);
        $token = MiniappService::miniappAccessToken($miniapps->appid,$miniapps->secret);
        if (!isset($token["access_token"])) return ["code"=>"1","msg"=>"access_token获取失败"];
        return response()->json(["code"=>"0","msg"=>"获取成功","result"=>["accessToken"=>$token["access_token"],"expireTime"=>time()+7200]]);
    }

    public function apiGetUrlscheme(Request $request)
    {
        if (empty($request->appid)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请输入APPID！"]);
        if (empty($request->links_id)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请输入外链ID！"]);
        $miniapps = Linkslistsminapps::getLinksListsMinappsByAppid($request->appid);
        $links = Linkslists::getLinks($request->links_id);
        if (empty($miniapps)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"小程序不存在！"]);
        if ($request->users_id != $miniapps->users_id) return response()->json(["status"=>"error","code"=>"1001","msg"=>"小程序不存在！"]);

        $urlscheme = WechatService::generateScheme($miniapps->appid,$miniapps->secret,$request->path,"id=".$request->links_id,$miniapps->original_id,$links->platfrom_type,$links->limit_pv);
        try {
            return response()->json(["code"=>"0","msg"=>"获取成功","result"=>["scheme"=>$urlscheme["urlscheme"]]]);
        } catch (Exception $e) {
            return response()->json(["code"=>"1","msg"=>$urlscheme["msg"]]);
        }
    }

    public function linksListsHuoma(Request $request)
    {
        if (empty($request->links_id)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请输入外链ID！"]);
        $huoma = Linkslistshuoma::getLinksListsHuoma($links_id);
        if (empty($huoma)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"活码不存在!"]);
        if ($huoma->end_time <= time()) return response()->json(["status"=>"error","code"=>"1001","msg"=>"会员已过期!"]);
        $backData = ["paddingStyle"=>"","iconUrl"=>"","iconBorderRadius"=>"","contactText"=>"","contactTextBlod"=>"","url"=>$huoma->work_url,"huoma_id"=>$huoma->huoma_id,"links_id"=>$huoma->links_id];
        return response()->json(["status"=>"success","code"=>"1000","msg"=>"获取成功","data"=>$backData]);
    }

    public function linksListsHuomaStatus(Request $request)
    {
        if (empty($request->links_id)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请输入外链ID！"]);
        if (empty($request->sign)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请输入签名！"]);
        // 获取签名
        $huoma_id = CommonService::aesDncryptone($request->sign);
        Linkslistshuoma::updateLinksListsHuomaState($huoma_id,2);
        return response()->json(["status"=>"success","code"=>"1000","msg"=>"操作成功!"]);
    }

    public function linksListsAdd(Request $request,$version)
    {
        try {
            $paramasExamine = LinkscheckService::linksParamasExamine($request);
            if ($paramasExamine["status"]=="error") return OutputService::error($paramasExamine["msg"],"",$paramasExamine["code"]);
            $user = Users::getUsersDetial($request->users_id);
            if ($user->disable == 2) return OutputService::error("此账号已被禁用无法创建链接，如有疑问请联系客服！");
            // 计算外链PV
            $usersLinksPv = LinkscheckService::getUsersLinksPv($request->users_id);
            if ($usersLinksPv["status"]=="error") return OutputService::error($usersLinksPv["msg"],"",1005);
            // 生成外链ID
            $links_id = CommonService::getRandomCodes(time().$request->users_id);
            // 获取跳转小程序
            $miniapp = LinkscheckService::getLinksListsMinapps($request,$links_id,$usersLinksPv["limit_pv"],"new");
            if ($miniapp["status"]=="error") return OutputService::error($miniapp["msg"],"",$miniapp["code"]);

            if (in_array($request->platfrom_type,[8,9,11,12])) {
                if (!empty($request->qrcodeLists)) {
                    $qrcodeLists = [];
                    $usersQrcodeLists = [];
                    foreach ($request->qrcodeLists as $qrcodeList) {
                        $qrcodeName = mb_substr($qrcodeList["name"],0,15);
                        $qrcodeLists[] = ["links_id"=>$links_id,"qrcodes_id"=>$qrcodeList["qrcodes_id"],"name"=>$qrcodeName,"img_url"=>$qrcodeList["img_url"],"expiration_time"=>strtotime($qrcodeList["expiration_time"]),"count_limit"=>$qrcodeList["count_limit"],"rate"=>$qrcodeList["rate"],"created_at"=>time()];
                        $usersQrcodeLists[] = ["links_id"=>$links_id,"qrcodes_id"=>$qrcodeList["qrcodes_id"],"img_url"=>$qrcodeList["img_url"],"users_id"=>$request->users_id,"status"=>1,"created_at"=>time()];
                    }
                    // 保存二维码图片
                    Linkslistsqrcodes::batchInsertLinksListsQrcodes($qrcodeLists);
                    Usersqrcodelists::batchInsertUserQrcodes($usersQrcodeLists);
                }
            }

            // 客服模式保存数据
            if (in_array($request->platfrom_type,[2,3])) {
                $services = [];
                foreach ($request->services as $key=>$service) {
                    $sort = $key+1;
                    if ($service["type"] == 3) {
                        $service_text = json_encode($service["text"]);
                    } else {
                        $service_text = $service["text"];
                    }
                    $services[] = ["links_id"=>$links_id,"sort"=>$sort,"type"=>$service["type"],"text"=>$service_text,"created_at"=>time()];
                }
                // 保存客服配置
                Linkslistskefu::batchInsertLinksListsKefu($services);
            }

            if ($request->platfrom_type == 6) {
                Linksliststhird::insertLinksListsThird($links_id,$request->miniapp["path"],$request->miniapp["appid"],$request->miniapp["original_id"]);
            }

            if ($request->qrcode_switch_type == "default") {
                $qrcode_switch = 2;
                $qrcode_upper = 1;
                $qrcode_daily = 500;
                $device_bind = 2;
                $work_time = 2;
                $qrcode_switch_type = "default";
            } else {
                $qrcode_switch = empty($request->qrcode_switch) ? 2 : $request->qrcode_switch;
                $qrcode_upper = empty($request->qrcode_upper) ? 1 : $request->qrcode_upper;
                $qrcode_daily = empty($request->qrcode_daily) ? 1 : $request->qrcode_daily;
                $device_bind = empty($request->device_bind) ? 2 : $request->device_bind;
                $work_time = empty($request->work_time) ? 2 : $request->work_time;
                $qrcode_switch_type = "custom";
            }

            if (in_array($request->platfrom_type,[1,10,13])) {
                $msg = $request->msg_url;
            } else {
                $msg = "";
            }


            $describe = mb_substr($request->describe,0,30);
            $nike = mb_substr($request->nike,0,34);
            // 添加小程序配置
            Linkslistssetting::createLinksListsSetting($links_id,$nike,$request->logo,$describe,$request->wechat,$request->button_show,$request->button_text,$request->miniapp_style,$request->service_notice,$request->service_image,$request->qrcode_notice,$device_bind,$work_time,$qrcode_switch_type,$request->sph_id,$request->sph_spid,$request->sph_img);

            // 给小程序添加默认样式
            Linkslistsstyles::createDefalutLinksListsStyles($links_id);
            //判断类型，是否用客服模式
            $authmini = Usersauthority::getUsersAuthority($request->users_id);
            $miniapp_status = $miniapp["status"];
            if(!empty($authmini) && $authmini->miniapp_style == 3){
                $miniapp_status = 3;
            }
            // 创建外链
            Linkslists::createLinkslists($request->users_id,$request->title,$msg,$usersLinksPv["limit_pv"],$usersLinksPv["limit_status"],$usersLinksPv["end_time"],$links_id,$request->platfrom,$request->platfrom_type,$miniapp["appid"],$miniapp["original_id"],$miniapp["path"],$miniapp["miniapp_type"],$qrcode_switch,$qrcode_upper,$qrcode_daily,$request->wechat,$miniapp_status);
            // 创建累计数据统计
            Linksliststotal::createLinkListTotal($links_id);

            $baiduSafe = LinkscheckService::baiduSafeCheck($request);
            if ($baiduSafe["status"]=="error") return OutputService::error($baiduSafe["msg"],"",1010);
            // 创建线上OSS
            Htmlosshanndle::dispatch($request->users_id,$links_id,date("Y-m-d H:i:s",time()))->delay(10);
            if ($usersLinksPv["limit_pv"] >= 1000) {
                return response()->json(['status' => 'success',"code"=>"1000", 'msg' => '外链创建成功,点击返回即可！','data'=>['links_id'=>$links_id,'url'=>'http://s.pdb2.com/l/'.$links_id]]);
            } else {
                return response()->json(['status' => 'success',"code"=>"1005", 'msg' => '外链创建成功,链接60分钟内有效；开通VIP无访问限制！','data'=>['links_id'=>$links_id]]);
            }
        } catch (Exception $e) {
            Log::info("linksListsAdd---Start");
            Log::info($e);
            Log::info($request->all());
            Log::info("linksListsAdd---End");
            return response()->json(['status' => 'error',"code"=>"1002", 'msg' => '外链创建失败,请联系微信客服为您处理！']);
        }
    }

    public function linksListsUpdate(Request $request)
    {
        try {
            // 审核外链
            $paramasExamine = LinkscheckService::linksParamasExamine($request);
            if ($paramasExamine["status"]=="error") return OutputService::error($paramasExamine["msg"],"",$paramasExamine["code"]);
            $links = Linkslists::getLinks($request->links_id);

            if(empty($links)) return OutputService::error("外链不存在！");
            $users = Users::getUsersDetial($request->users_id);
            if($users->authority != 3 && $links->users_id != $request->users_id) return OutputService::error("外链不存在！");
            if($links->disable == 2) return OutputService::error("外链已被删除！");
            if($users->disable == 2) return OutputService::error("此账号已被禁用无法更新链接，如有疑问请联系客服！");
            // 获取跳转小程序
            $miniapp = LinkscheckService::getLinksListsMinapps($request,$request->links_id,$links->limit_pv,"update");
            if ($miniapp["status"]=="error") return OutputService::error($miniapp["msg"],"",$miniapp["code"]);

            if (in_array($request->platfrom_type,[8,9,11,12])) {
                $linksAllQrcodes = Linkslistsqrcodes::linksAllListsQrcodesId($request->links_id);
                $oldQrcodesIds = $linksAllQrcodes->pluck("qrcodes_id")->all();
                $qrcodeLists = collect($request->qrcodeLists);
                $newQrcodesIds = $qrcodeLists->pluck("qrcodes_id")->all();

                // 获取新增加的二维码
                $newqrcodes = array_diff($newQrcodesIds,$oldQrcodesIds);
                // 获取删除了的二维码
                $deleteqrcodes = array_diff($oldQrcodesIds,$newQrcodesIds);

                if (!empty($newqrcodes)) {
                    $nqrcodeLists = [];
                    $usersQrcodeLists = [];
                    // 添加二维码
                    foreach ($newqrcodes as $newqrcode) {
                        $qrcodeList = $qrcodeLists->where("qrcodes_id",$newqrcode)->first();
                        $qrcodeName = mb_substr($qrcodeList["name"],0,15);
                        $nqrcodeLists[] = ["links_id"=>$request->links_id,"qrcodes_id"=>$qrcodeList["qrcodes_id"],"name"=>$qrcodeName,"img_url"=>$qrcodeList["img_url"],"expiration_time"=>strtotime($qrcodeList["expiration_time"]),"count_limit"=>$qrcodeList["count_limit"],"rate"=>$qrcodeList["rate"],"created_at"=>time()];
                        $usersQrcodeLists[] = ["links_id"=>$request->links_id,"qrcodes_id"=>$qrcodeList["qrcodes_id"],"img_url"=>$qrcodeList["img_url"],"users_id"=>$request->users_id,"status"=>1,"created_at"=>time()];
                    }
                    Linkslistsqrcodes::batchInsertLinksListsQrcodes($nqrcodeLists);
                    Usersqrcodelists::batchInsertUserQrcodes($usersQrcodeLists);
                }

                if (!empty($deleteqrcodes)) {
                    // 删除二维码
                    foreach ($deleteqrcodes as $deleteqrcode) {
                        Linkslistsqrcodes::deleteLinksListsQrcodes($deleteqrcode);
                        Usersqrcodelists::deleteUserQrcodes($deleteqrcode);
                    }
                }

                // 只修改了原来的二维码
                $existUpdate = false;
                $usersQrcodeLists = [];
                foreach ($linksAllQrcodes as $linksAllQrcode) {
                    $qrcodeList = $qrcodeLists->where("qrcodes_id",$linksAllQrcode->qrcodes_id)->first();
                    if (!empty($qrcodeList)) {
                        $qrcodeName = mb_substr($qrcodeList["name"],0,15);
                        if ($qrcodeList["img_url"] != $linksAllQrcode->img_url || $qrcodeList["count_limit"] != $linksAllQrcode->count_limit || $qrcodeList["rate"] != $linksAllQrcode->rate || strtotime($qrcodeList["expiration_time"]) != $linksAllQrcode->expiration_time || $qrcodeName != $linksAllQrcode->name) {
                            $existUpdate = true;
                            Linkslistsqrcodes::updateLinksListsQrcodes($linksAllQrcode->qrcodes_id,$qrcodeName,$qrcodeList["img_url"],strtotime($qrcodeList["expiration_time"]),$qrcodeList["rate"],$qrcodeList["count_limit"]);
                            if ($qrcodeList["img_url"] != $linksAllQrcode->img_url) {
                                $usersQrcodeLists[] = ["links_id"=>$request->links_id,"qrcodes_id"=>$linksAllQrcode->qrcodes_id,"img_url"=>$qrcodeList["img_url"],"users_id"=>$request->users_id,"status"=>2,"created_at"=>time()];
                            }
                        }
                    }
                }
                if (!empty($usersQrcodeLists)) {
                    Usersqrcodelists::batchInsertUserQrcodes($usersQrcodeLists);
                }
                // 如果二维码有变动,则删除二维码的缓存
                if (!empty($newqrcodes) || !empty($newqrcodes) || $existUpdate) CacheService::removeLinksQrcodeCache($request->links_id);
            }

            // 客服模式保存数据
            if (in_array($request->platfrom_type,[2,3])) {
                $services = [];
                foreach ($request->services as $key=>$service) {
                    $sort = $key+1;
                    if ($service["type"] == 3) {
                        $service_text = json_encode($service["text"]);
                    } else {
                        $service_text = $service["text"];
                    }
                    $services[] = ["links_id"=>$request->links_id,"sort"=>$sort,"type"=>$service["type"],"text"=>$service_text,"created_at"=>time()];
                }
                // 删除原来的客服配置
                Linkslistskefu::deleteLinksListsAllKefu($request->links_id);
                // 保存客服配置
                Linkslistskefu::batchInsertLinksListsKefu($services);
            }

            if ($request->platfrom_type == 6) {
                Linksliststhird::updateLinksListsThird($request->links_id,$request->miniapp["path"],$request->miniapp["appid"],$request->miniapp["original_id"]);
            }

            $qrcode_switch = empty($request->qrcode_switch) ? 2 : $request->qrcode_switch;
            $qrcode_upper = empty($request->qrcode_upper) ? 1 : $request->qrcode_upper;
            $qrcode_daily = empty($request->qrcode_daily) ? 1 : $request->qrcode_daily;

            if (in_array($request->platfrom_type,[1,10,13])) {
                $msg = $request->msg_url;
            } else {
                $msg = "";
            }

            $describe = mb_substr($request->describe,0,30);
            $nike = mb_substr($request->nike,0,34);
            // 更新小程序配置            
            Linkslistssetting::updateLinksListsSetting($request->links_id,$nike,$request->logo,$describe,$request->wechat,$request->button_show,$request->button_text,$request->miniapp_style,$request->service_notice,$request->service_image,$request->qrcode_notice,$request->device_bind,$request->work_time,$request->qrcode_switch_type,$request->sph_id,$request->sph_spid,$request->sph_img);

            // 更新外链
            Linkslists::updateLinkslists($request->links_id,$request->title,$msg,$request->platfrom,$request->platfrom_type,$miniapp["appid"],$miniapp["original_id"],$miniapp["path"],$miniapp["miniapp_type"],$qrcode_switch,$qrcode_upper,$qrcode_daily,$request->wechat,$miniapp["status"]);

            $baiduSafe = LinkscheckService::baiduSafeCheck($request);
            // 删除短链接缓存数据
            CacheService::removeLinksCache($request->links_id);
            // 更新线上OSS
            Htmlosshanndle::dispatch($links->users_id,$links->links_id,$links->created_at)->delay(10);
            if ($baiduSafe["status"]=="error") return OutputService::error($baiduSafe["msg"],"",1010);
            return OutputService::success("外链更新成功,3秒后跳转外链详情！");
        } catch (Exception $e) {
            Log::info("linksListsUpdate---Start");
            Log::info($e);
            Log::info($request->all());
            Log::info("linksListsUpdate---End");
            return response()->json(['status' => 'error',"code"=>"1002", 'msg' => '外链更新失败,请联系微信客服为您处理！']);
        }
    }

    public function linksQrcodeLists(Request $request)
    {
        if (empty($request->links_id)) return OutputService::error("参数错误");
        $links = Linkslists::getLinksSimple($request->links_id);
        if (empty($links)) return OutputService::error("参数错误");
        if ($request->users_id != $links->users_id) return OutputService::error("参数错误");
        $linkListQrcodes = Linkslistsqrcodes::linkQrcodeLists($request->links_id);
        return OutputService::success("SUCCESS",$linkListQrcodes);
    }

    public function linksListsQrcodesAdd(Request $request)
    {
        if(empty($request->multiple)){
            if (empty($request->links_id)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"参数错误！"]);
            if (empty($request->qrcode)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请上传二维码！"]);
            if (empty($request->expiration_time)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请选择二维码过期时间！"]);
            if (empty($request->rate)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请设置二维码权重！"]);
            if (empty($request->count_limit)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请设置二维码访问上限！"]);
            if (mb_strlen($request->qrcodes_name) > 15) return response()->json(["status"=>"error","code"=>"1001","msg"=>"二维码名称不能超过15个字"]);
            $links = Linkslists::getLinksSimple($request->links_id);
            if (empty($links)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"链接不存在！"]);
            if ($request->users_id != $links->users_id) return response()->json(["status"=>"error","code"=>"1001","msg"=>"链接不存在！"]);
            $qrcodenumber = Linkslistsqrcodes::getUseAbleQrcodeCount($request->links_id);
            if($qrcodenumber > 199) return response()->json(["status"=>"error","code"=>"1001","msg"=>"链接子码已达上限"]);
            $lastqrcode = Linkslistsqrcodes::getFirstLinksListsQrcode($request->links_id);
            $qrcodes_id = CommonService::getRandomCodes($request->users_id.time().rand(1000,9999));
            Linkslistsqrcodes::addLinksListsQrcodes($request->links_id,$qrcodes_id,$request->qrcodes_name,$request->qrcode,strtotime($request->expiration_time),$request->rate,$request->count_limit);
            Usersqrcodelists::batchInsertUserQrcodes(["links_id"=>$request->links_id,"qrcodes_id"=>$qrcodes_id,"img_url"=>$request->qrcode,"users_id"=>$request->users_id,"status"=>1,"created_at"=>time()]);
            // 删除二维码缓存
            CacheService::removeLinksQrcodeCache($request->links_id);
            return response()->json(["status"=>"success","code"=>"1000","msg"=>"二维码添加成功!","qrcodes_id"=>$qrcodes_id]);
        }else{
            if (empty($request->links_id)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"参数错误！"]);
            if (empty($request->expiration_time)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请选择二维码过期时间！"]);
            if (empty($request->rate)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请设置二维码权重！"]);
            if (empty($request->count_limit)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请设置二维码访问上限！"]);
            if (empty($request->qrcode)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请上传二维码！"]);
            if (is_array($request->qrcode) && count($request->qrcode) === 0) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请上传二维码！"]);
            $links = Linkslists::getLinksSimple($request->links_id);
            if (empty($links)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"链接不存在！"]);
            if ($request->users_id != $links->users_id) return response()->json(["status"=>"error","code"=>"1001","msg"=>"链接不存在！"]);
            $qrcodenumber = Linkslistsqrcodes::getUseAbleQrcodeCount($request->links_id);
            if($qrcodenumber > 199) return response()->json(["status"=>"error","code"=>"1001","msg"=>"链接子码已达上限"]);
            $qrcodelength = count($request->qrcode);
            if($qrcodelength > 10) return response()->json(["status"=>"error","code"=>"1001","msg"=>"每次不能超过10个二维码"]);
            foreach ($request->qrcode as $qrcode) {
                $qrcodes_id = CommonService::getRandomCodes($request->users_id.time().rand(1000,9999));
                $name = empty($qrcode['name']) ? time() : mb_substr($qrcode['name'],0,15);
                Linkslistsqrcodes::addLinksListsQrcodes($request->links_id,$qrcodes_id,$name,$qrcode['image'],strtotime($request->expiration_time),$request->rate,$request->count_limit);
                Usersqrcodelists::batchInsertUserQrcodes(["links_id"=>$request->links_id,"qrcodes_id"=>$qrcodes_id,"img_url"=>$qrcode['image'],"users_id"=>$request->users_id,"status"=>1,"created_at"=>time()]);  
            }
            $msg = '成功添加了'.$qrcodelength.'个二维码';
            // 删除二维码缓存
            CacheService::removeLinksQrcodeCache($request->links_id);
            return response()->json(["status"=>"success","code"=>"1000","msg"=>$msg]);
        }
    }

    public function linksListsQrcodesUpdate(Request $request)
    {
        if (empty($request->qrcodes_id) || empty($request->links_id)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"参数错误！"]);
        if (empty($request->qrcode)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请上传二维码！"]);
        if (empty($request->expiration_time)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请选择二维码过期时间！"]);
        if (empty($request->rate)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请设置二维码权重！"]);
        if (empty($request->count_limit)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"请设置二维码访问上限！"]);
        if (mb_strlen($request->qrcodes_name) > 15) return response()->json(["status"=>"error","code"=>"1001","msg"=>"二维码名称不能超过15个字"]);
        $links = Linkslists::getLinksSimple($request->links_id);
        if (empty($links)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"链接不存在！"]);
        if ($request->users_id != $links->users_id) return response()->json(["status"=>"error","code"=>"1001","msg"=>"链接不存在！"]);
        $oldQrcodeList = Linkslistsqrcodes::getLinkListQrcodeByQrcodeId($request->qrcodes_id);
        if (empty($oldQrcodeList)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"活码不存在!"]);
        if ($oldQrcodeList->img_url != $request->qrcode) {
            Usersqrcodelists::batchInsertUserQrcodes(["links_id"=>$request->links_id,"qrcodes_id"=>$request->qrcodes_id,"img_url"=>$request->qrcode,"users_id"=>$request->users_id,"status"=>2,"created_at"=>time()]);
        }
        Linkslistsqrcodes::updateLinksListsQrcodes($request->qrcodes_id,$request->qrcodes_name,$request->qrcode,strtotime($request->expiration_time),$request->rate,$request->count_limit);
        // 删除二维码缓存
        CacheService::removeLinksQrcodeCache($request->links_id);
        return response()->json(["status"=>"success","code"=>"1000","msg"=>"二维码更新成功!"]);
    }

    public function linksListsQrcodesDelete(Request $request)
    {
        if (empty($request->qrcodes_id) || empty($request->links_id)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"参数错误！"]);
        $links = Linkslists::getLinksSimple($request->links_id);
        if (empty($links)) return response()->json(["status"=>"error","code"=>"1001","msg"=>"链接不存在！"]);
        if ($request->users_id != $links->users_id) return response()->json(["status"=>"error","code"=>"1001","msg"=>"链接不存在！"]);
        if ($request->status > 1) {
            $useAbleQrcode = Linkslistsqrcodes::getOnlineQrcodeCount($request->links_id);
            if ($useAbleQrcode <= 1) return response()->json(["status"=>"error","code"=>"1001","msg"=>"删除/下架后无可用二维码,请新增一个后再删除!"]);
        }
        if ($request->status == 3) {
            Linkslistsqrcodes::deleteLinksListsQrcodes($request->qrcodes_id);
            $message = "二维码删除成功!";
        } elseif ($request->status == 1) {
            Linkslistsqrcodes::updateLinkListQrcodeStatus($request->qrcodes_id,1);
            $message = "二维码上架成功,已开启展示!";
        } else {
            Linkslistsqrcodes::updateLinkListQrcodeStatus($request->qrcodes_id,2);
            $message = "二维码下架成功,已关闭展示!";
        }
        Usersqrcodelists::deleteUserQrcodes($request->qrcodes_id);
        // 删除二维码缓存
        CacheService::removeLinksQrcodeCache($request->links_id);
        return response()->json(["status"=>"success","code"=>"1000","msg"=>$message]);
    }
}
